package cn.relx.basic.rocket;

import cn.relx.basic.config.JmsConfig;
import cn.relx.order.domain.OrderPetAcquisition;
import cn.relx.order.mapper.OrderPetAcquisitionMapper;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(consumerGroup = "pet_group_order",nameServer =JmsConfig.NAME_SERVER,topic = "order_topic")
public class SpringBootConsumer implements RocketMQListener {

    @Autowired
    private OrderPetAcquisitionMapper orderPetAcquisitionMapper;

    private Long searchMasterMsgId;

    @Override
    public void onMessage(Object msg) {
        Long id = Long.valueOf(String.valueOf(msg));
        OrderPetAcquisition orderPetAcquisition = orderPetAcquisitionMapper.findById(id);
            if(orderPetAcquisition != null){
                orderPetAcquisition.setState(-1);
                orderPetAcquisitionMapper.update(orderPetAcquisition);
            }

    }

    public void setId(Long id){
        this.searchMasterMsgId = id;
    }
}